package leetcode.editor.cn.basic;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }


    public ListNode add(int... args){
        ListNode node = new ListNode();
        ListNode head = node;
        ListNode curr = node;
        for (int arg : args) {
            if (curr.next == null) {
                curr.next = new ListNode(arg);
                curr = curr.next;
            }
        }
        return head.next;
    }


    @Override
    public String toString() {
        return "ListNode{" +
                "val=" + val +
                ", next=" + next +
                '}';
    }

    public static void main(String[] args){
        ListNode listNode = new ListNode();
        System.out.println(listNode.add(2,1,3).toString());

    }
}